


// 获取搜索框value
$('.searchText>input').val()
$('.searchText button').on({
    click() {
        $('.searchText>a').attr('href', `search.html?keyword=${$('.searchText>input').val()}&subjectId=&type=&courseType=`)
    }
})
// 直播列表接口
var num = 0;
var str;
request('http://wkt.myhope365.com//pc/liveCourseInfo/list', type = "post", header = 1).then((res) => {
    // 添加右侧ul
    $('.liveClass>.right').append(`<ul id="titles"></ul>`);
    // 左侧添加ul
    $('.liveClass>.left').append(`<ul id="contents"></ul>`);
    $.each(res.rows, function (index, value) {
        if (value.liveStatus == 0) {
            str = '未开播'
        } else if (value.liveStatus == 1) {
            str = '正在直播'
        } else if (value.liveStatus == 2) {
            str = '直播结束'
        }

        // 左侧内容
        $('.liveClass>.left>ul').append(`
            <li style="display:block;background-image:url(${value.course.coverFileUrl})">
                <h3>${value.course.courseTitle}</h3>
                <span><img src="images/选中.png" alt="">${str}</span>
                <button>${str}</button>
            </li>
        `);

        // 直播列表
        $('.liveClass>.right>ul').append(`
            <li>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=">
                    <span class="iconfont icon-xuanzhong1"></span>
                    <span>直播结束</span>
                    <span>${value.course.courseTitle}</span>
                </a>
            </li>
        `);
    })
    // tab切换
    $('#titles>li').mouseenter(function () {
        $('#contents>li').css('display', 'none').eq($(this).index()).css('display', 'block');
    })
})
// 轮播图接口
request('http://wkt.myhope365.com//weChat/applet/course/banner/list?number').then((res) => {
    $.each(res.data, function (index, value) {
        $('.swiper-wrapper').append(`
            <div class= "swiper-slide">
                <a href="https://course.myhope365.com/other/course/detail/${value.id}" target="_blank" style="background-image:url(${value.imgUrlPc})">
                </a>
            </div >
        `);
    })
    var mySwiper = new Swiper('.swiper-container', {
        direction: 'horizontal', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },

        // 如果需要滚动条
        // scrollbar: {
        //     el: '.swiper-scrollbar',
        // },
    })

})

// 免费课程分类接口
request('http://wkt.myhope365.com//pc/course/search/keyword', type = "get",
    {
        pageNum: 1,
        pageSize: 10,
        type: 'free',
    }
).then((res) => {
    $('.freeClass').append('<ul></ul>')
    $.each(res.courseList, function (index, value) {
        if (value.isFree == 1) {
            price = '免费'
        } else {
            price = `<span style="color:red">￥${value.discountPrice}</span><span style="color:#999;font-size:12px;text-decoration: line-through;margin-left:4px">￥${value.coursePrice}</span>`
        }
        $('.freeClass>ul').append(
            `<li>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=" target="_blank">
                    <img src="${value.coverFileUrl}" alt="">
                </a>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=" target="_blank">${value.courseTitle}</a>
                <span>共${value.subSectionNum}节课 | ${value.learningNum}人报名</span><br><span>${price}</span>
            </li>`
        );
    })
})
// 精品课程分类接口
request('http://wkt.myhope365.com//pc/course/search/keyword', type = "get",
    {
        pageNum: 1,
        pageSize: 5,
        type: 'boutique',
    }
).then((res) => {
    $('.fineClass').append('<ul></ul>')
    $.each(res.courseList, function (index, value) {
        if (value.isFree == 1) {
            price = '免费'
        } else {
            price = `<span style="color:red">￥${value.discountPrice}</span><span style="color:#999;font-size:12px;text-decoration: line-through;margin-left:4px">￥${value.coursePrice}</span>`
        }
        if (value.isDiscount == 1) {
            $('.fineClass>ul>li:last-child').append(`<a href="detail.html?id=${value.courseId}" class="discount">${value.discountDesc}</a>`);
        }
        $('.fineClass>ul').append(
            `<li>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=" target="_blank">
                    <img src="${value.coverFileUrl}" alt="">
                </a>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=" target="_blank">${value.courseTitle}</a>
                <span>共${value.subSectionNum}节课 | ${value.learningNum}人报名</span><br><span>${price}</span>
            </li>`
        );
    })
})
// 限时折扣
request('http://wkt.myhope365.com//pc/course/search/keyword', type = "get",
    {
        pageNum: 1,
        pageSize: 5,
        type: 'discount',
    }
).then((res) => {
    $('.discountClass').append('<ul></ul>')
    $.each(res.courseList, function (index, value) {
        if (value.isFree == 1) {
            price = '免费'
        } else {
            price = `<span style="color:red">
                        ￥${value.discountPrice}
                    </span>
                    <span style="color:#999;font-size:12px;text-decoration: line-through;margin-left:4px">
                        ￥${value.coursePrice}
                    </span>`
        }
        if (value.isDiscount == 1) {
            $('.fineClass>ul>li:last-child').append(`
                <a href="detail.html?id=${value.courseId}" class="discount">
                    ${value.discountDesc}
                </a>
            `);
        }
        $('.discountClass>ul').append(
            `<li>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=" target="_blank">
                    <img src="${value.coverFileUrl}" alt="">
                </a>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=" target="_blank">${value.courseTitle}</a>
                <span>共${value.subSectionNum}节课 | ${value.learningNum}人报名</span><br><span>${price}</span>
            </li>`
        );
    })
})
// 头条精选
request('http://wkt.myhope365.com//pc/course/search/keyword', type = "get",
    {
        pageNum: 1,
        pageSize: 5,
        type: 'discount',
    }
).then((res) => {
    $('.headlinesClass').append('<ul></ul>')
    $.each(res.courseList, function (index, value) {
        $('.headlinesClass>ul').append(
            `<li>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=" target="_blank">
                    <img src="${value.coverFileUrl}" alt="">
                </a>
                <a href="detail.html?keyword=&id=${value.courseId}&subjectId=&type=&courseType=" target="_blank">${value.courseTitle}</a>
            </li>`
        )
    })
})

// 搜索框变色
borderColor($('.searchText>input'), '#00cf8c', '#ccc')
function borderColor(who, beforeColor, afterColor) {
    who.on(
        {
            focus() {
                who.css('border-color', beforeColor)
            },
            blur() {
                who.css('border-color', afterColor)
            }
        })
}
// QQ
qqChangeColor();
function qqChangeColor() {
    $.each($('.QQ>li'), function () {
        $(this).on({
            mouseenter() {
                $(this).children('a').children('img').attr("src", "images/qq白.png")
            },
            mouseleave() {
                $(this).children('a').children('img').attr("src", "images/qq.png")
            }
        })
    })
}




